package com.softserveinc.moviedbapp.adapter;

import android.content.res.Resources;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.util.Log;

import com.softserveinc.moviedbapp.R;
import com.softserveinc.moviedbapp.fragment.MovieListFragment;
import com.viewpagerindicator.TitleProvider;

import java.util.List;

public class MovieListFragmentAdapter extends FragmentPagerAdapter implements TitleProvider {

	private final List<MovieListFragment> movieListFragments;

	private static String TAG = MovieListFragmentAdapter.class.getSimpleName();
	private static final boolean DEBUG = false;
	private static String[] CONTENT;

	public MovieListFragmentAdapter(final FragmentManager fm, final List<MovieListFragment> fragments,
			final Resources resources) {
		super(fm);
		movieListFragments = fragments;
		CONTENT = new String[] { resources.getString(R.string.by_title), resources.getString(R.string.by_release_date),
				resources.getString(R.string.by_rating) };
		if (DEBUG) {
			Log.i(TAG, "MovieListFragmentAdapter(fm) constructor");
		}
	}

	@Override
	public Fragment getItem(final int position) {
		if (DEBUG) {
			Log.i(TAG, "getItem(final int position) pos = " + position);
		}
		return movieListFragments.get(position);
	}

	@Override
	public int getCount() {
		if (DEBUG) {
			Log.i(TAG, "getCount()");
		}
		return movieListFragments.size();
	}

	@Override
	public int getItemPosition(final Object object) {
		if (DEBUG) {
			Log.i(TAG, "getItemPosition(final Object object) = " + POSITION_NONE);
		}
		return POSITION_NONE;
	}

	@Override
	public String getTitle(final int position) {
		if (DEBUG) {
			Log.i(TAG, "getTitle(final int position) pos = " + position);
		}
		return CONTENT[position];
	}
}
